package cn.gotom.pinggu.action;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import cn.gotom.core.service.UniversalService;
import cn.gotom.core.web.Constants;
import cn.gotom.core.web.action.MenuInf;
import cn.gotom.pinggu.pojos.Cpzl;
import cn.gotom.pinggu.pojos.Sjcjb;
import cn.gotom.pinggu.pojos.Sjcjbmx;
import cn.gotom.pinggu.pojos.Ylpw;
import cn.gotom.pinggu.service.DataService;
import cn.gotom.pinggu.vo.Nsrxx;

import com.google.inject.Inject;

/**
 * 新建采建Action(即采集表明细Action)
 * 
 * @author longjun
 * 
 */
public class SjcjbmxAction implements MenuInf
{
	protected final Logger log = Logger.getLogger(getClass());

	@Inject
	private UniversalService universalService;
	private Sjcjbmx sjcjbmx;
	private Sjcjb sjcjb;
	private Nsrxx nsrxx;
	private List<Cpzl> cpzlList;
	private List<Ylpw> ylpwList;
	@Inject
	private DataService dataService;
	private String actionmsg;

	public String taxpayer()
	{
		return "taxpayer";
	}

	public String findtaxpayer()
	{
		if (StringUtils.isEmpty(nsrxx.getNsrdm()) && StringUtils.isEmpty(nsrxx.getNsrmc()))
		{
			setActionmsg("请输入纳税人代码或名称！");
			return "taxpayer";
		}
		// Nsrxx nsr = null;
		// if (StringUtils.isNotEmpty(nsrxx.getNsrdm()))
		// {
		// nsr = dataService.getNsrxxByNsrdm(nsrxx.getNsrdm());
		// }
		// else if (StringUtils.isNotEmpty(nsrxx.getNsrmc()))
		// {
		// nsr = dataService.getNsrxxByNsrdm(nsrxx.getNsrmc());
		// }
		// if (nsr == null)
		// {
		// setActionmsg("该纳税人不存在，请输入正确的纳税人信息！");
		// return "taxpayer";
		// }
		return inputmx();
	}

	public String input()
	{
		setActionmsg("");
		if (nsrxx == null)
		{
			nsrxx = new Nsrxx();
		}
		return "taxpayer";
	}

	public String inputmx()
	{
		sjcjbmx = new Sjcjbmx();
		cpzlList = universalService.findAll(Cpzl.class);
		ylpwList = universalService.findAll(Ylpw.class);
		if (sjcjb == null)
		{
			sjcjb = new Sjcjb();
			sjcjb.setNsrdm(nsrxx.getNsrdm());
			sjcjb.setNsrmc(nsrxx.getNsrmc());
		}
		return Constants.SUCCESS;
	}

	public String list()
	{
		cpzlList = universalService.findAll(Cpzl.class);
		ylpwList = universalService.findAll(Ylpw.class);
		return Constants.SUCCESS;
	}

	public String save()
	{
		if (StringUtils.isNotEmpty(sjcjb.getNsrdm()))
		{
			if (!universalService.exists(Sjcjb.class, sjcjb.getId()))
			{
				sjcjb = (Sjcjb) universalService.persist(sjcjb);
			}
			sjcjbmx = (Sjcjbmx) universalService.persist(sjcjbmx);
		}
		return Constants.LIST;
	}

	@Override
	public String getName()
	{
		return "新建采集";
	}

	@Override
	public String getGroupName()
	{
		return "数据采集";
	}

	public List<Cpzl> getCpzlList()
	{
		return cpzlList;
	}

	@Override
	public int getMenuSort()
	{
		return 300;
	}

	public void setCpzlList(List<Cpzl> cpzlList)
	{
		this.cpzlList = cpzlList;
	}

	public List<Ylpw> getYlpwList()
	{
		return ylpwList;
	}

	public void setYlpwList(List<Ylpw> ylpwList)
	{
		this.ylpwList = ylpwList;
	}

	public Sjcjbmx getSjcjbmx()
	{
		return sjcjbmx;
	}

	public void setSjcjbmx(Sjcjbmx sjcjbmx)
	{
		this.sjcjbmx = sjcjbmx;
	}

	public Sjcjb getSjcjb()
	{
		return sjcjb;
	}

	public void setSjcjb(Sjcjb sjcjb)
	{
		this.sjcjb = sjcjb;
	}

	public Nsrxx getNsrxx()
	{
		return nsrxx;
	}

	public void setNsrxx(Nsrxx nsrxx)
	{
		this.nsrxx = nsrxx;
	}

	public String getActionmsg()
	{
		return actionmsg;
	}

	public void setActionmsg(String actionmsg)
	{
		this.actionmsg = actionmsg;
	}
}
